SVGTransform

Part of wslib

see also: SVG, SVGObject

The SVGTransform object holds transformation data. It can be added to every SVGObject, in the transfom slot.

In the SVG file format the 'transform' element has a bit unusual form. It contains a string with pseudo code. For example:

"translate( 20, 10 ) scale( 1.5 ) rotate( 45, 0, 0 )"

this would convert into GUI.pen functions as follows:

SVGTransform( "translate( 20, 10 ) scale( 1.5 ) rotate( 45, 0, 0 )" ).asGUICode;

/* result:

GUI.pen.translate( 20, 10 );

GUI.pen.scale( 1.5, 1.5 );

GUI.pen.rotate( 0.7853981633974483, 0, 0 );

*/

All SVGObjects convert 'transform' argument internally to SVGTransform:

(

SVGRect( 0, 0, 100, 100,

strokeColor: "green",

transform: "translate(100, 10) scale(0.5, 2.5) rotate(12.7, 0, 0)" ).plot;

)

instance variables

string

The SVG transform element formatted string

dict

an array with sub-arrays, parsed from the string in the following format:

[ \type, [ ... arguments ] ]

SVGTransform( "translate( 20, 10 ) scale( 1.5 ) rotate( 45, 0, 0 )" ).dict;

SVGTransform( [[ \translate, [ 20, 10 ]], [\scale, [ 1.5 ]], [\rotate, [ 45, 0, 0 ]]] ).string;

creation

SVGTransform ( string )

string : can also be an array in the dict format

instance methods

string_ ( newString )

set the string and updates the dict accordingly

dict_ ( newDict )

set the dict and updates the string accordingly

addToString

concatenates a string to the existing string (updates the dict accordingly)

addToDict

adds an element to the existing dict (updates the string accordingly)

asPenFunction

returns a function for drawing

asGUICode ( penClass )

returns GUI.pen style code as a string